const Router = require("koa-router");
const multer = require("../../utils/multer");

// 创建路由对象
const router = new Router();

const handleMulterError = async (ctx, next) => {
  try {
    await multer.array("avatar")(ctx, next);
    if (ctx.req?.status) {
      ctx.body = ctx.req.status;
    } else {
      ctx.body = {
        code: 1,
        data: null,
        msg: "上传成功",
      };
    }
  } catch (err) {
    ctx.body = {
      code: 0,
      data: null,
      msg: err.code,
    };
  }
};

router.post("/", handleMulterError, (ctx) => {
  ctx.response.body = {
    code: 1,
    data: null,
    msg: "上传成功",
  };
});

module.exports = router;
